package com.bw.polling.view

import android.view.View
import android.widget.PopupMenu
import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.base.view.BaseActivity
import com.bw.common.adapter.FragmentAdapter
import com.bw.common.entity.MyTab
import com.bw.polling.R
import com.bw.polling.databinding.ActivityPollDetailBinding
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener
/**
 *  智慧园区-07 -点位详情 -v1.1-张梦停
 *  2025/05/13
 */
@Route(path = "/poll/detail")
class PollDetailActivity : BaseActivity<ActivityPollDetailBinding>() {
    val data = arrayListOf<CustomTabEntity>()
    val list = arrayListOf<Fragment>()
    lateinit var fragmentAdapter: FragmentAdapter
    override fun initView() {
        binding.pollDetailTop.ivBack.setOnClickListener { finish() }
        binding.pollDetailTop.tvTitle.text = "点位详情"
        binding.pollDetailTop.ivMore.visibility = View.VISIBLE
        binding.pollDetailTop.ivMore.setOnClickListener {
            val menu = PopupMenu(this, binding.pollDetailTop.ivMore)
            menu.inflate(R.menu.item_menu22)
            menu.setOnMenuItemClickListener {
                when(it.itemId){
                    R.id.awite-> {
                        ARouter.getInstance().build("/poll/await").navigation()
                        true
                    }
                    else -> false
                }

            }
            menu.show()
        }
        list.add(BlankFragment1())
        list.add(BlankFragment2())
        list.add(BlankFragment3())
        fragmentAdapter = FragmentAdapter(this,list)
        binding.vp.adapter = fragmentAdapter
        data.add(MyTab("巡检标准", 0, 0))
        data.add(MyTab("巡检记录",0,0))
        data.add(MyTab("工单记录", 0,0))
        binding.tl.setTabData(data)
        binding.tl.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                binding.vp.setCurrentItem(position)
            }
            override fun onTabReselect(position: Int) {}
        })
        binding.vp.registerOnPageChangeCallback(object : OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                binding.tl.setCurrentTab(position)
            }
        })

    }

    override fun initData() {

    }

}